<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/6
 * Time: 5:47 PM
 */

namespace App\Entities;

use App\Models\UserCouponModel;

class UserCouponEntity extends ABaseEntity
{
    public function __construct(UserCouponModel $model)
    {
        $this->model = $model;
    }

    /**
     * @param int $couponId
     * @return UserCouponEntity|null
     */
    public static function findByCouponId(int $couponId)
    {
        $model = UserCouponModel::where('coupon_id', $couponId)->first();
        if (is_null($model)) {
            return null;
        }
        return new self($model);
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->model->id;
    }

    /**
     * @return string
     */
    public function getCode(): string
    {
        return $this->model->code;
    }

    /**
     * @param string $code
     */
    public function setCode(string $code): void
    {
        $this->model->code = $code;
    }

    /**
     * @return int
     */
    public function getCouponId()
    {
        return $this->model->coupon_id;
    }

    /**
     * @return int
     */
    public function getCouponGroupId()
    {
        return $this->model->coupon_group_id;
    }

    /**
     * @deprecated
     * @return int
     */
    public function used()
    {
        return $this->isUsed();
    }

    /**
     * @return int
     */
    public function isUsed()
    {
        return $this->model->used;
    }

    /**
     * @return int
     */
    public function getUserId()
    {
        return $this->model->user_id;
    }

    /**
     * @return string
     */
    public function getCreatedAt()
    {
        return $this->model->created_at;
    }

    /**
     * @return string
     */
    public function getUpdatedAt()
    {
        return $this->model->updated_at;
    }

    /**
     * @param int $val
     */
    public function setOrderId(int $val)
    {
        $this->model->order_id = $val;
    }

    /**
     * @return int
     */
    public function getOrderId()
    {
        return $this->model->order_id;
    }

    /**
     * @param int $val
     */
    public function setUsed(int $val)
    {
        $this->model->used = $val;
    }
}
